<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../../css/app.css">
    <link rel="stylesheet" type="text/css" href="../comm/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/tabBar.css">
    <link rel="stylesheet" type="text/css" href="../comm/shop_comm.css" />
    <link rel="stylesheet" type="text/css" href="../comm/icon.css" />
    <link rel="stylesheet" type="text/css" href="./upgrade_fm.css">
    <title>推荐</title>
</head>

<body>
    <div id="app" @click="hideFm">
        <div class="upgrade_fm_win" @click.stop style="display:none">
            <div class="upgrade_fm_win_banner">
                <img src="../../../image/member/header.png" alt="">
            </div>
            <div class="upgrade_fm_win_title">
                <div class="upgrade_fm_win_title_">
                    <div class="upgrade_fm_win_title_box">
                        <div class="upgrade_fm_win_title_box_title">
                            升级任务 <span v-text="MemberGoodsData.already_buy_num+'/'+MemberGoodsData.total_need_buy">0/2</span>
                        </div>
                        <div class="upgrade_fm_win_title_box_text">
                            须完成以下所有任务才可以升级哦~
                        </div>
                    </div>
                </div>
            </div>
            <!-- 商品列表 -->
            <div class="upgrade_fm_win_con">
                <div v-for="(item,index) in MemberGoodsData.goods" :class="item.recommend_goods==0?'upgrade_fm_win_list upgrade_fm_win_list_re':'upgrade_fm_win_list'">
                    <div class="upgrade_fm_win_list_box" @click="toGoods_detail(item.goods_id,item.is_buy)" >
                        <!-- 角标 -->
                        <div class="upgrade_fm_win_list_box_jbiao" v-if="item.is_buy==1" style="background:#efefef;color:#888">
                            已购买
                        </div>
                        <div class="upgrade_fm_win_list_box_jbiao upgrade_fm_win_list_box_org" v-else-if="item.recommend_goods==1">
                            推荐人
                        </div>
                        <div class="upgrade_fm_win_list_box_jbiao upgrade_fm_win_list_box_org_re" v-else>
                            <span v-text="item.star"></span>级星品
                        </div>
                        <div class="upgrade_fm_win_list_left">
                            <img :src="item.cover+'?x-oss-process=image/resize,m_lfit,w_200'" alt="">
                        </div>
                        <div class="upgrade_fm_win_list_center">
                            <div class="upgrade_fm_win_list_center_box">
                                <div class="upgrade_fm_win_list_center_box_name">
                                    <span class="text2" v-text="item.name">阿萨德杀鸡阿四大皆空阿四大皆空</span>
                                </div>
                                <div class="upgrade_fm_win_list_center_box_money" @click.stop>
                                    <!-- <span class="upgrade_fm_win_list_center_money_msg">会员价</span> -->
                                    <span class="upgrade_fm_win_list_center_num" v-text="'￥'+item.sale_price">￥198</span>&nbsp;
                                    <span v-if="item.is_buy==0" class="upgrade_fm_win_list_center_re" @click="getMemberOne(index,item.recommend_goods)"><i class="iconfont icon-shuaxin"></i>换一个</span>
                                </div>
                            </div>
                        </div>
                        <div class="upgrade_fm_win_list_right">
                            <span :style="item.is_buy==1?'background:#efefef !important;color:#888 !important':''" v-text="item.is_buy==1?'已购买':'立即购买'"></span>
                        </div>
                    </div>
                </div>

                <!-- 邀请好友的任务 -->
                <div class="upgrade_fm_win_list share" v-if="show_invite==1">
                    <div class="upgrade_fm_win_list_box">
                        <!-- 角标end -->
                        <div class="upgrade_fm_win_list_left">
                            <div class="upgrade_fm_win_list_left_icon">
                                <i class="iconfont icon-yaoqing"></i>
                            </div>
                        </div>
                        <div class="upgrade_fm_win_list_center" style="height:15vw">
                            <div class="upgrade_fm_win_list_center_box">
                                <div class="upgrade_fm_win_list_center_box_name">
                                    <span class="text2" v-text="invite.title">邀请好友</span>
                                </div>
                                <div class="upgrade_fm_win_list_center_box_money">
                                    <span class="upgrade_fm_win_list_center_money_msg">任务进度：</span>
                                    <span class="upgrade_fm_win_list_center_num" v-text="invite.junior_num+'/'+invite.total_num">0/10</span>
                                </div>
                            </div>
                        </div>
                        <div class="upgrade_fm_win_list_right">
                            <span @click="ShareCode" :style="invite.junior_num==invite.total_num?'background:#efefef;color:#888':''" v-text="invite.junior_num==invite.total_num?'已完成':'邀请好友'"></span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 商品列表end -->
        </div>
    </div>
</body>
<script src="../../sea.js" data-main="../../main"></script>
<script type="text/javascript" src="../../vue.js"></script>
<script type="text/javascript">
    apiready = function() {
        seajs.use(["../../api", "../../jquery", "../../app", "../../service", ], function($api, $, app, service) {
            var vm = {
                el: "#app",
                data: {
                    MemberGoodsData: [],
                    invite:{},
                    show_invite:0
                },
                mounted: function() {
                    var that = this
                    api.addEventListener({
                        name: 'getMemberGoods'
                    }, function(ret, err) {

                        that.getMemberGoods()
                    });

                },
                methods: {
                    // 获取单个商品
                    getMemberOne: function(index, recommend_goods) {
                        var that = this;
                        app.ajax(service.getMemberOne, {
                            data: {
                                values: {
                                    unionid: api.pageParam.unionid,
                                    type: recommend_goods,
                                    mask: "none"
                                }
                            }
                        }, function(res) {
                            if (res.code == 0) {
                                Vue.set(that.MemberGoodsData.goods, index, res.data)
                            }
                        })
                    },
                    // 前往商品详情
                    toGoods_detail:function (goods_id,is_buy) {
                      if(is_buy==1){
                        return
                      }
                      api.openWin({
                          name: 'goods_detail',
                          url: '../buy_goods/goods.html',
                          pageParam: {
                              goodsId: goods_id,
                              isSeller:0
                          },
                          reload:true
                      });
                      // $('.upgrade_fm_win').hide()
                      // api.setFrameAttr({
                      //     name: 'upgrade_fm',
                      //     hidden:true
                      // });

                    },
                    // 转发给好友
                    ShareCode:function(url){
                      // 查找海报文件文件
                      var that = this
                      if(this.invite.junior_num==this.invite.total_num){
                        api.toast({
                            msg: '该任务已完成',
                            duration: 2000,
                            location: 'bottom'
                        });
                        return
                      }
                      api.readFile({
                          path: api.cacheDir+'/upload/shareCode.png'
                      }, function(ret, err) {
                          if (ret.status) {//有这个海报
                              that.wxShare()
                          } else {//没有该海报需要重新下载，名称固定为shareCode.png
                              that.getdownShareCode()
                          }
                      });
                    },
                    // 请求获取海报
                    getdownShareCode:function(){
                      var that = this;
                      app.ajax(service.openShopShare, {
                          data: {
                              values: {
                                  unionid: api.pageParam.unionid,
                                  mask: "正在生成海报"
                              }
                          }
                      }, function(res) {
                          if (res.code == 0) {
                            api.download({
                                url:res.data,
                                cache: true,
                                savePath: api.cacheDir + '/upload/shareCode.png',
                                allowResume: true
                            }, function(ret, err) {
                                if (ret.state == 1) {
                                    that.wxShare()
                                }
                                if (ret.state == 2) {
                                    api.toast({
                                        msg: ret.msg,
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                }
                            });
                          }else{
                            if(res.code==559){//没有上传会员商品
                              setTimeout(function(){
                                $app.openWin('shopEditMember', {
                                    shopId: $api.getStorage('user').data.shop_code
                                })
                              },2000)
                            }
                          }
                      })
                    },
                    // 微信分享
                    wxShare:function(url){
                      var wx = api.require('wx');
                      wx.shareImage({
                          scene: 'session',
                          contentUrl: api.cacheDir + '/upload/shareCode.png'
                      }, function(ret, err) {

                      });
                    },
                    //获取会员商品
                    getMemberGoods: function() {
                        var that = this;
                        app.ajax(service.getMemberGoods, {
                            data: {
                                values: {
                                    unionid: api.pageParam.unionid,
                                    mask: "none"
                                }
                            }
                        }, function(res) {
                            if (res.code == 0) {
                                that.MemberGoodsData = res.data;
                                that.show_invite = res.data.show_invite
                                that.invite = res.data.invite
                                that.$nextTick(function() {
                                    $('.upgrade_fm_win').slideDown(200)
                                })
                            }
                        })
                    },
                    hideFm: function() {
                      api.setFrameAttr({
                          name: 'upgrade_fm',
                          hidden: true
                      });
                      $('.upgrade_fm_win').hide()
                    }
                }
            }
            var even = function() {}
            var newVue = new Vue(vm);
            even();
        })
    }
</script>

</html>
